using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_PromotionManage_SaleView : Member, IRequiresSessionState
{
	private string linkHead = "";
	private Shop_Order _shop_order = null;
	protected ScriptManager ScriptManager1;
	protected Literal ltrProType;
	protected TextBox TxtOrderFormNum;
	protected TextBox TxtUserName;
	protected TextBox TxtBeginDate;
	protected TextBox TxtEndDate;
	protected Button QuickSearchBtn;
	protected DropDownList DropMoment;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	protected UpdatePanel UpdatePanel4;
	protected Shop_Order shop_order
	{
		get
		{
			Shop_Order shop_order;
			if (this._shop_order == null)
			{
				this._shop_order = new Shop_Order(this.conn);
				shop_order = this._shop_order;
			}
			else
			{
				shop_order = this._shop_order;
			}
			return shop_order;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPromotionPower(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.TxtBeginDate.Attributes.Add("onclick", "SelectDate(" + this.TxtBeginDate.UniqueID + ",'yyyy-MM-dd');");
			this.TxtEndDate.Attributes.Add("onclick", "SelectDate(" + this.TxtEndDate.UniqueID + ",'yyyy-MM-dd');");
			this.ltrProType.Text = "积分商品——";
			this.BindDate();
		}
	}
	protected void BindDate()
	{
		string whereStr = this.QueryString();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		int num2 = 10;
		int saleOrderRecordCount = this.shop_order.GetSaleOrderRecordCount(whereStr, base.user.UserID, null);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		DataTable saleOrderPage = this.shop_order.GetSaleOrderPage(whereStr, base.user.UserID, startIndex, endIndex, null);
		this.rptList.DataSource = saleOrderPage;
		this.rptList.DataBind();
		decimal d = 0m;
		decimal d2 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			int num3 = i + 1;
			if (num > 0)
			{
				num3 = (num - 1) * num2 + num3;
			}
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			label.Text = num3.ToString();
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfPresentExpTotal");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfTotal");
			if (!string.IsNullOrEmpty(hiddenField.Value) && !string.IsNullOrEmpty(hiddenField2.Value))
			{
				decimal d3 = hiddenField2.Value.ToDecimal2();
				decimal d4 = hiddenField.Value.ToDecimal2();
				d2 += d3;
				d += d4;
			}
		}
		Label label2 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalPresentExpTotal");
		Label label3 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalMoney");
		label2.Text = d.ToString();
		label3.Text = d2.ToString();
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string url = "SaleView.aspx?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, num2, saleOrderRecordCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url);
	}
	protected string QueryString()
	{
		string text = " and TradeType=5 ";
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.TxtBeginDate.Text = text2;
		}
		else
		{
			text2 = this.TxtBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			if (!Text.IsDate(text2))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			text = text + " and DATEDIFF(DD, updateTime,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.TxtEndDate.Text = text3;
		}
		else
		{
			text3 = this.TxtEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!Text.IsDate(text3))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + " and DATEDIFF(DD, updateTime,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("cousmentName");
		if (!string.IsNullOrEmpty(text4))
		{
			this.TxtUserName.Text = text4;
		}
		else
		{
			text4 = this.TxtUserName.Text;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and BuyerName like '%" + text4.Trim() + "%'";
			this.linkHead = this.linkHead + "&cousmentName=" + text4;
		}
		string text5 = Fetch.Get("qsearch");
		if (!string.IsNullOrEmpty(text5))
		{
			this.DropMoment.ddlSelect(text5);
		}
		else
		{
			text5 = this.DropMoment.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text5))
		{
			string text6 = text5;
			if (text6 != null)
			{
				if (!(text6 == "7"))
				{
					if (!(text6 == "10"))
					{
						if (!(text6 == "30"))
						{
							if (!(text6 == "month"))
							{
								if (text6 == "year")
								{
									text += " and (DATEDIFF(YYYY,UpdateTime,GETDATE())=0)";
								}
							}
							else
							{
								text += " and (DATEDIFF(MM,UpdateTime,GETDATE())=0)";
							}
						}
						else
						{
							text += " and (UpdateTime>=DATEADD(MM,-1,GETDATE()) and UpdateTime<=DATEADD(MM,1,getdate()))";
						}
					}
					else
					{
						text += " and (DATEDIFF(DD,UpdateTime,GETDATE())>=0 and DATEDIFF(DD,UpdateTime,GETDATE())<=10)";
					}
				}
				else
				{
					text += " and (DATEDIFF(DD,UpdateTime,GETDATE())>=0 and DATEDIFF(DD,UpdateTime,GETDATE())<=7)";
				}
			}
			this.linkHead = this.linkHead + "&qsearch=" + text5;
		}
		string text7 = Fetch.Get("StrOrderForm");
		if (!string.IsNullOrEmpty(text7))
		{
			this.TxtOrderFormNum.Text = text7;
		}
		else
		{
			text7 = this.TxtOrderFormNum.Text;
		}
		if (!string.IsNullOrEmpty(text7))
		{
			text = text + " and OrderFormNum like '%" + text7.Trim() + "%'";
			this.linkHead = this.linkHead + "&StrOrderForm=" + text7;
		}
		return text;
	}
	protected void QuickSearchBtn_Click(object sender, EventArgs e)
	{
		this.BindDate();
	}
}
